#include <stdio.h>

int main(int argc, char *argv[]) {

    int year, month;
    int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    scanf("%d %d", &year, &month);
    if((year%4==0&&year%100!=0)||year%400==0){
        if(month==2){
            printf("29");
        }else{
            printf("%d",days[month - 1]);
        }
    }else{
        printf("%d", days[month - 1]);
    }

    return 0;
}